// 登录验证

let sbmEle = document.querySelector(".sbm1");
sbmEle.onclick = function() {
	let phoneEle = document.querySelector(".ipt1");
	let pswEle = document.querySelector(".ipt2");
	let phoneval = phoneEle.value;
	let pswval = pswEle.value;
	if (phoneval == "" || pswval == "") {
		alert("请输入用户名和密码");
	} else {
		//发送ajax
		ajax({
			method: "get",
			url: "./checkregister.php",
			data: {
				phonenum: phoneval,
				password: pswval
			},
		}).then(res => {
			console.log(res)//{"status":1,"info":"\u7528\u6237\u540d\u6b63\u786e"}
			let obj = JSON.parse(res);
			console.log(obj);//{status: 1, info: '用户名正确'}
			
			if (obj.status == "0") {
				alert("账号或密码错误!");
				phoneEle.value = "";
				pswEle.value = "";
			} else if (obj.status == "1") {
				alert("登录成功!");
				let objRes = obj.res;
				localStorage.setItem("username",objRes.phonenum);
				localStorage.setItem("id",objRes.id);
				window.location.href = "./index.html";
			} else {
				alert("该手机号未注册,请注册之后使用");
			}
		})
	}
}
